package com.gw.quotes.adapter;

import java.text.SimpleDateFormat;
import java.util.List;

import android.content.Context;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gw.quotes.R;
import com.gw.quotes.entity.business.ProjectInfoEntity.ProjectInfo.Projectquotation;
import com.gw.quotes.entity.business.ProjectInfoEntity.ProjectInfo.Projectquotation.Accquotation;

public class QuoteAccquotationAdapter extends BaseAdapter {

	private List<Projectquotation> list;
	private Context context;
	private int resource;

	public QuoteAccquotationAdapter(Context context, int layoutId,
			List<Projectquotation> list) {
		this.context = context;
		this.resource = layoutId;
		this.list = list;
	}

	@Override
	public int getCount() {
		return this.list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Projectquotation projectquotation = list.get(position);
		LinearLayout layout = null;
		if (convertView == null) {
			layout = (LinearLayout) LayoutInflater.from(this.context).inflate(
					resource, null);
		} else {
			layout = (LinearLayout) convertView;
		}
		TextView quote_time = (TextView) layout
				.findViewById(R.id.quote_time_text);
		TextView quote_price = (TextView) layout
				.findViewById(R.id.quote_price_text);
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		quote_time.setText(df.format(projectquotation.getQuotationtime()));
		quote_price.setText(String.format("￥%.2f",
				projectquotation.getTotalpric()));
		return layout;
	}

}
